home *** CD-ROM | disk | FTP | other *** search
/ Libris Britannia 4 / science library(b).zip / science library(b) / ASTRNOMY / EPHEM421.ZIP / ALTMENUS.C < prev    next >
C/C++ Source or Header  |  1990-09-13  |  11KB  |  392 lines

  1. /* printing routines for the three alternative bottom half menus,
  2.  * "menu1", "menu2" and "menu3".
  3.  */
  4.  
  5. #include <stdio.h>
  6. #include <math.h>
  7. #include "astro.h"
  8. #include "circum.h"
  9. #include "screen.h"
  10.  
  11. static int altmenu = F_MNU1;    /* which alternate menu is up; one of F_MNUi */
  12. static int alt2_stdhzn;    /* whether to use STDHZN (aot ADPHZN) horizon algthm  */
  13. static int alt3_geoc;    /* whether to use geocentric (aot topocentric) vantage*/
  14.  
  15. /* table of screen rows given a body #define from astro/h or screen.h */
  16. static short bodyrow[NOBJ] = {
  17.     R_MERCURY, R_VENUS, R_MARS, R_JUPITER, R_SATURN,
  18.     R_URANUS, R_NEPTUNE, R_PLUTO, R_SUN, R_MOON, R_OBJX, R_OBJY
  19. };
  20. /* table of screen cols for third menu format, given body #define ... */
  21. static short bodycol[NOBJ] = {
  22.     C_MERCURY, C_VENUS, C_MARS, C_JUPITER, C_SATURN,
  23.     C_URANUS, C_NEPTUNE, C_PLUTO, C_SUN, C_MOON, C_OBJX, C_OBJY
  24. };
  25.  
  26. /* initialize altmenu; used by main from cracking the ephem startup file.
  27.  */
  28. altmenu_init (n)
  29. int n;
  30. {
  31.     altmenu = n;
  32. }
  33.  
  34. /* let op decide which alternate menu should be up,
  35.  * including any menu-specific setup they might require.
  36.  * return 0 if things changed to require updating the alt menu; else -1.
  37.  */
  38. altmenu_setup()
  39. {
  40.     static char *flds[5] = {
  41.         "Data menu", "Rise/Set menu", "Separations menu"
  42.     };
  43.     int newmenu = altmenu, newhzn = alt2_stdhzn, newgeoc = alt3_geoc;
  44.     int new;
  45.     int fn = altmenu == F_MNU1 ? 0 : altmenu == F_MNU2 ? 1 : 2;
  46.  
  47.     ask:
  48.     flds[3]= newhzn ? "Standard hzn" : "Adaptive hzn";
  49.     flds[4]= newgeoc? "Geocentric" : "Topocentric";
  50.  
  51.     switch (popup (flds, fn, 5)) {
  52.     case 0: newmenu = F_MNU1; break;
  53.     case 1: newmenu = F_MNU2; break;
  54.     case 2: newmenu = F_MNU3; break;
  55.     case 3: newhzn ^= 1; fn = 3; goto ask;
  56.     case 4: newgeoc ^= 1; fn = 4; goto ask;
  57.     default: return (-1);
  58.     }
  59.  
  60.     new = 0;
  61.     if (newmenu != altmenu) {
  62.         altmenu = newmenu;
  63.         new++;
  64.     }
  65.     if (newhzn != alt2_stdhzn) {
  66.         alt2_stdhzn = newhzn;
  67.         if (newmenu == F_MNU2)
  68.         new++;
  69.     }
  70.     if (newgeoc != alt3_geoc) {
  71.         alt3_geoc = newgeoc;
  72.         if (newmenu == F_MNU3)
  73.         new++;
  74.     }
  75.     return (new ? 0 : -1);
  76. }
  77.  
  78. /* erase the info for the given planet */
  79. alt_nobody (p)
  80. int p;
  81. {
  82.     f_eol (bodyrow[p], C_RA);
  83. }
  84.  
  85. alt_body (b, force, np)
  86. int b;        /* which body, ala astro.h and screen.h defines */
  87. int force;    /* if !0 then draw for sure, else just if changed since last */
  88. Now *np;
  89. {
  90.     switch (altmenu) {
  91.     case F_MNU1: alt1_body (b, force, np); break;
  92.     case F_MNU2: alt2_body (b, force, np); break;
  93.     case F_MNU3: alt3_body (b, force, np); break;
  94.     }
  95. }
  96.  
  97. /* draw the labels for the current alternate menu format */
  98. alt_labels ()
  99. {
  100.     switch (altmenu) {
  101.     case F_MNU1: alt1_labels (); break;
  102.     case F_MNU2: alt2_labels (); break;
  103.     case F_MNU3: alt3_labels (); break;
  104.     }
  105. }
  106.  
  107. /* erase the labels for the current alternate menu format */
  108. alt_nolabels ()
  109. {
  110.     int i;
  111.  
  112.     f_string (R_ALTM, C_ALTMV, "             ");
  113.     for (i = R_PLANTAB; i < R_SUN; i++)
  114.         f_eol (i, C_RA);
  115. }
  116.  
  117. alt_menumask()
  118. {
  119.     return (altmenu);
  120. }
  121.  
  122. /* handy function to return the next planet in the order in which they are
  123.  * displayed in the lower half of the screen.
  124.  * input is a given planet, return is the next planet.
  125.  * if input is not legal, then first planet is returned; when input is the
  126.  * last planet, then -1 is returned.
  127.  * typical usage is something like:
  128.  *   for (p = nxtbody(-1); p != -1; p = nxtbody(p))
  129.  */
  130. nxtbody(p)
  131. int p;
  132. {
  133.     static short nxtpl[NOBJ] = {
  134.         VENUS, MARS, JUPITER, SATURN, URANUS,
  135.         NEPTUNE, PLUTO, OBJX, MOON, MERCURY, OBJY, -1
  136.     };
  137.  
  138.     if (p < MERCURY || p >= NOBJ)
  139.         return (SUN);
  140.     else
  141.         return (nxtpl[p]);
  142. }
  143.  
  144. static
  145. alt1_labels()
  146. {
  147.     f_string (R_ALTM, C_ALTMV, "  Planet Data");
  148.  
  149.     f_string (R_PLANTAB,    C_RA+2,    "R.A.");
  150.     f_string (R_PLANTAB,    C_DEC+2,"Dec");
  151.     f_string (R_PLANTAB,    C_AZ+2,    "Az");
  152.     f_string (R_PLANTAB,    C_ALT+2,"Alt");
  153.     f_string (R_PLANTAB,    C_HLONG,"H Long");
  154.     f_string (R_PLANTAB,    C_HLAT,    "H Lat");
  155.     f_string (R_PLANTAB,    C_EDIST,"Ea Dst");
  156.     f_string (R_PLANTAB,    C_SDIST,"Sn Dst");
  157.     f_string (R_PLANTAB,    C_ELONG,"Elong");
  158.     f_string (R_PLANTAB,    C_SIZE,    "Size");
  159.     f_string (R_PLANTAB,    C_MAG,    "VMag");
  160.     f_string (R_PLANTAB,    C_PHASE,"Phs");
  161. }
  162.  
  163. static
  164. alt2_labels()
  165. {
  166.     f_string (R_ALTM, C_ALTMV, "Rise/Set Info");
  167.  
  168.     f_string (R_PLANTAB,    C_RISETM-2,    "Rise Time");
  169.     f_string (R_PLANTAB,    C_RISEAZ,    "Rise Az");
  170.     f_string (R_PLANTAB,    C_TRANSTM-2,    "Trans Time");
  171.     f_string (R_PLANTAB,    C_TRANSALT-1,    "Trans Alt");
  172.     f_string (R_PLANTAB,    C_SETTM-1,    "Set Time");
  173.     f_string (R_PLANTAB,    C_SETAZ,    "Set Az");
  174.     f_string (R_PLANTAB,    C_TUP-1,    "Hours Up");
  175. }
  176.  
  177. static
  178. alt3_labels()
  179. {
  180.     f_string (R_ALTM, C_ALTMV, "  Separations");
  181.  
  182.     f_string (R_PLANTAB,    C_SUN,        " Sun");
  183.     f_string (R_PLANTAB,    C_MOON,        "Moon");
  184.     f_string (R_PLANTAB,    C_MERCURY,    "Merc");
  185.     f_string (R_PLANTAB,    C_VENUS,    "Venus");
  186.     f_string (R_PLANTAB,    C_MARS,        "Mars");
  187.     f_string (R_PLANTAB,    C_JUPITER,    " Jup");
  188.     f_string (R_PLANTAB,    C_SATURN,    " Sat");
  189.     f_string (R_PLANTAB,    C_URANUS,    "Uranus");
  190.     f_string (R_PLANTAB,    C_NEPTUNE,    " Nep");
  191.     f_string (R_PLANTAB,    C_PLUTO,    "Pluto");
  192.     f_string (R_PLANTAB,    C_OBJX,        "  X");
  193.     f_string (R_PLANTAB,    C_OBJY,        "  Y");
  194. }
  195.  
  196. /* print body info in first menu format */
  197. static
  198. alt1_body (p, force, np)
  199. int p;        /* which body, as in astro.h/screen.h defines */
  200. int force;    /* whether to print for sure or only if things have changed */
  201. Now *np;
  202. {
  203.     Sky sky;
  204.     double as = plot_ison() || srch_ison() ? 0.0 : 60.0;
  205.     int row = bodyrow[p];
  206.  
  207.     if (body_cir (p, as, np, &sky) || force) {
  208.         f_ra (row, C_RA, sky.s_ra);
  209.         f_angle (row, C_DEC, sky.s_dec);
  210.         if (sky.s_hlong != NOHELIO) {
  211.         f_angle (row, C_HLONG, sky.s_hlong);
  212.         if (p != SUN)
  213.             f_angle (row, C_HLAT, sky.s_hlat);
  214.         }
  215.  
  216.         if (p == MOON) {
  217.         /* distance is on km, show in miles */
  218.         f_double (R_MOON, C_EDIST, "%6.0f", sky.s_edist/1.609344);
  219.         } else if (sky.s_edist > 0.0) {
  220.         /* show distance in au */
  221.         f_double (row, C_EDIST,(sky.s_edist>=10.0)?"%6.3f":"%6.4f",
  222.                                 sky.s_edist);
  223.         }
  224.         if (sky.s_sdist > 0.0)
  225.         f_double (row, C_SDIST, (sky.s_sdist>=10.0)?"%6.3f":"%6.4f",
  226.                                 sky.s_sdist);
  227.         if (p != SUN)
  228.         f_double (row, C_ELONG, "%6.1f", sky.s_elong);
  229.         if (p != OBJX && p != OBJY)
  230.         f_double (row, C_SIZE, (p==MOON||p==SUN)?"%4.0f":"%4.1f",
  231.                                 sky.s_size);
  232.         f_double (row, C_MAG, (p==MOON||p==SUN)?"%4.0f":"%4.1f",
  233.                                     sky.s_mag);
  234.         if (sky.s_sdist > 0.0) {
  235.         /* some terminals scroll when write a char in low-right corner.
  236.          * TODO: is there a nicer way to handle this maybe?
  237.          */
  238.         int col = row == NR ? C_PHASE - 1 : C_PHASE;
  239.         /* would just do this if Turbo-C 2.0 "%?.0f" worked:
  240.          * f_double (row, col, "%3.0f", sky.s_phase);
  241.          */
  242.         f_int (row, col, "%3d", sky.s_phase);
  243.         }
  244.     }
  245.  
  246.     f_angle (row, C_AZ, sky.s_az);
  247.     f_angle (row, C_ALT, sky.s_alt);
  248. }
  249.  
  250. /* print body info in the second menu format */
  251. static
  252. alt2_body (p, force, np)
  253. int p;        /* which body, as in astro.h/screen.h defines */
  254. int force;    /* whether to print for sure or only if things have changed */
  255. Now *np;
  256. {
  257.     double ltr, lts, ltt, azr, azs, altt;
  258.     int row = bodyrow[p];
  259.     int status;
  260.     double tmp;
  261.     int today_tup = 0;
  262.  
  263.     /* always recalc OBJX and Y since we don't know it's the same object */
  264.     if (!riset_cir (p, np, p==OBJX || p==OBJY, alt2_stdhzn?STDHZN:ADPHZN,
  265.         <r, <s, <t, &azr, &azs, &altt, &status) && !force)
  266.         return;
  267.  
  268.     alt_nobody (p);
  269.  
  270.     if (status & RS_ERROR) {
  271.         /* can not find where body is! */
  272.         f_string (row, C_RISETM, "?Error?");
  273.         return;
  274.     }
  275.     if (status & RS_CIRCUMPOLAR) {
  276.         /* body is up all day */
  277.         f_string (row, C_RISETM, "Circumpolar");
  278.         if (status & RS_NOTRANS)
  279.         f_string (row, C_TRANSTM, "No transit");
  280.         else {
  281.         f_mtime (row, C_TRANSTM, ltt);
  282.         if (status & RS_2TRANS)
  283.             f_char (row, C_TRANSTM+5, '+');
  284.         f_angle (row, C_TRANSALT, altt);
  285.         }
  286.         f_string (row, C_TUP, "24:00"); /*f_mtime() changes to 0:00 */
  287.         return;
  288.     }
  289.     if (status & RS_NEVERUP) {
  290.         /* body never up at all today */
  291.         f_string (row, C_RISETM, "Never up");
  292.         f_mtime (row, C_TUP, 0.0);
  293.         return;
  294.     }
  295.  
  296.     if (status & RS_NORISE) {
  297.         /* object does not rise as such today */
  298.         f_string (row, C_RISETM, "Never rises");
  299.         ltr = 0.0; /* for TUP */
  300.         today_tup = 1;
  301.     } else {
  302.         f_mtime (row, C_RISETM, ltr);
  303.         if (status & RS_2RISES) {
  304.         /* object rises more than once today */
  305.         f_char (row, C_RISETM+5, '+');
  306.         }
  307.         f_angle (row, C_RISEAZ, azr);
  308.     }
  309.  
  310.     if (status & RS_NOTRANS)
  311.         f_string (row, C_TRANSTM, "No transit");
  312.     else {
  313.         f_mtime (row, C_TRANSTM, ltt);
  314.         if (status & RS_2TRANS)
  315.         f_char (row, C_TRANSTM+5, '+');
  316.         f_angle (row, C_TRANSALT, altt);
  317.     }
  318.  
  319.     if (status & RS_NOSET) {
  320.         /* object does not set as such today */
  321.         f_string (row, C_SETTM, "Never sets");
  322.         lts = 24.0;    /* for TUP */
  323.         today_tup = 1;
  324.     } else {
  325.         f_mtime (row, C_SETTM, lts);
  326.         if (status & RS_2SETS)
  327.         f_char (row, C_SETTM+5, '+');
  328.         f_angle (row, C_SETAZ, azs);
  329.     }
  330.  
  331.     tmp = lts - ltr;
  332.     if (tmp < 0)
  333.         tmp = 24.0 + tmp;
  334.     f_mtime (row, C_TUP, tmp);
  335.     if (today_tup)
  336.         f_char (row, C_TUP+5, '+');
  337. }
  338.  
  339. /* print body info in third menu format. this may be either the geocentric
  340.  *   or topocentric angular separation between object p and each of the others.
  341.  *   the latter, of course, includes effects of refraction and so can change
  342.  *   quite rapidly near the time of each planets rise or set.
  343.  * for now, we don't save old values so we always redo everything and ignore
  344.  *  the "force" argument. this isn't that bad since body_cir() has memory and
  345.  *   will avoid most computations as we hit them again in the lower triangle.
  346.  * we are limited to only 5 columns per object. to make it fit, we display
  347.  *   degrees:minutes if less than 100 degrees, otherwise just whole degrees.
  348.  */
  349. /*ARGSUSED*/
  350. static
  351. alt3_body (p, force, np)
  352. int p;        /* which body, as in astro.h/screen.h defines */
  353. int force;    /* whether to print for sure or only if things have changed */
  354. Now *np;
  355. {
  356.     int row = bodyrow[p];
  357.     Sky skyp, skyq;
  358.     double spy, cpy, px, *qx, *qy;
  359.     int wantx = obj_ison(OBJX);
  360.     int wanty = obj_ison(OBJY);
  361.     double as = plot_ison() || srch_ison() ? 0.0 : 60.0;
  362.     int q;
  363.  
  364.     (void) body_cir (p, as, np, &skyp);
  365.     if (alt3_geoc) {
  366.         /* use ra for "x", dec for "y". */
  367.         spy = sin (skyp.s_dec);
  368.         cpy = cos (skyp.s_dec);
  369.         px = skyp.s_ra;
  370.         qx = &skyq.s_ra;
  371.         qy = &skyq.s_dec;
  372.     } else {
  373.         /* use azimuth for "x", altitude for "y". */
  374.         spy = sin (skyp.s_alt);
  375.         cpy = cos (skyp.s_alt);
  376.         px = skyp.s_az;
  377.         qx = &skyq.s_az;
  378.         qy = &skyq.s_alt;
  379.     }
  380.     for (q = nxtbody(-1); q != -1; q = nxtbody(q))
  381.         if (q != p && (q != OBJX || wantx) && (q != OBJY || wanty)) {
  382.         double sep, dsep;
  383.         (void) body_cir (q, as, np, &skyq);
  384.         sep = acos(spy*sin(*qy) + cpy*cos(*qy)*cos(px-*qx));
  385.         dsep = raddeg(sep);
  386.         if (dsep >= (100.0 - 1.0/60.0/2.0))
  387.             f_int (row, bodycol[q], "%5d:", dsep);
  388.         else
  389.             f_angle (row, bodycol[q], sep);
  390.         }
  391. }
  392.